class AgeError(Exception):
    def __init__(self, code, msg):
        super().__init__(self)
        self.code = code
        self.msg = msg

    def __str__(self):
        return "AgeError {{ code: {}, msg: {} }}".format(self.code, self.msg)


class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    @property
    def age(self):
        return self.__age

    @age.setter
    def age(self, age):
        if age < 0 or age > 120:
            raise AgeError(1001, "年龄必须介于0~120之间")
        self.__age = age


try:
    p = Person("张三", 1500)
    print(p.name, p.age)
except AgeError as e:
    print(e)
except Exception as e:
    print(e)
